#ifndef _HAL_IIC_H
#define _HAL_IIC_H
#include "main.h"

#define AT24C01		127
#define AT24C02		255
#define AT24C04		511
#define AT24C08		1023
#define AT24C16		2047
#define AT24C32		4095
#define AT24C64	    8191
#define AT24C128	16383
#define AT24C256	32767  

#define EE_TYPE  AT24C04

//SCL
#define SetSCL(x)        HAL_GPIO_WritePin(EEPROM_SCL_GPIO_Port, EEPROM_SCL_Pin, x)          //@7M_WRITE_PIN(EEPROM_PORT_SCL, EEPROM_PIN_SCL, x)
#define SetSDA(x)        HAL_GPIO_WritePin(EEPROM_SDA_GPIO_Port, EEPROM_SDA_Pin, x)          //@7M_WRITE_PIN(EEPROM_PORT_SDA, EEPROM_PIN_SDA, x)

#define SetEEPROM_WP(x)  HAL_GPIO_WritePin(EEPROM_WR_GPIO_Port,  EEPROM_WR_Pin,  x)      		 	//@7M_WRITE_PIN(EEPROM_PORT_WP, EEPROM_PIN_WP, x)
#define SDA_read         HAL_GPIO_ReadPin(EEPROM_SDA_GPIO_Port,  EEPROM_SDA_Pin)  				//@7M_READ_PIN(EEPROM_PORT_SDA, EEPROM_PIN_SDA)



//#define SDA_IN()  M_SET_PIN_IN(EEPROM_PORT_SDA, EEPROM_PIN_SDA)//输入模式
//#define SDA_OUT() M_SET_PIN_OUT(EEPROM_PORT_SDA, EEPROM_PIN_SDA)//输出模式
              


//#define SDA_IN()  	{PORT_SDA->MODER &= ~(3<<(7*2)); PORT_SDA->MODER |= 0<<(7*2);} //输入模式
//#define SDA_OUT() 	{PORT_SDA->MODER &= ~(3<<(7*2)); PORT_SDA->MODER |= 1<<(7*2);} //输出模式

#define SCL_H         SetSCL(1)
#define SCL_L         SetSCL(0)
#define SDA_H         SetSDA(1)
#define SDA_L         SetSDA(0)


#define EEPROM_WP_H		SetEEPROM_WP(1)
#define EEPROM_WP_L		SetEEPROM_WP(0)
extern HAL_StatusTypeDef OnEEPROMWrite(uint16_t addr, uint8_t *writebuff, uint16_t writelen);
extern HAL_StatusTypeDef OnEEPROMRead(uint16_t addr, uint8_t *retbuff, uint16_t retlen);
extern uint8_t OnEEPROMWriteTest(void);
#endif

